//JS操作cookies方法! 
//写cookies 
function setCookie(name,value) 
{ 
    var Days = 30; 
    var exp = new Date(); 
    exp.setTime(exp.getTime() + Days*24*60*60*1000); 
    document.cookie = name + "="+ escape (value) + ";Path=/;Domain=.hupu.com;expires=" + exp.toGMTString(); 
} 
//读取cookies 
function getCookie(name) 
{ 
    var arr,reg=new RegExp("(^| )"+name+"=([^;]*)(;|$)");
 
    if(arr=document.cookie.match(reg))
        return unescape(arr[2]); 
    else 
        return null; 
} 

//删除cookies 
function delCookie(name) 
{ 
	var Days = 365; 
    var exp = new Date(); 
    exp.setTime(exp.getTime() - Days*24*60*60*1000); 
    var cval=getCookie(name); 
    if(cval!=null) 
        document.cookie= name + "="+cval+";Path=/;Domain=.hupu.com;expires="+exp.toGMTString(); 
}
//跨域种cookie 
function logincookieHideImg(uid, tag, notJump){

	//设置超时 时间
	var timeout = 1800;
	var domaincount = 0;
	for(var i = 0; i < domains.length; i++) {
		load();
	}
	function load() {
		var freeLogin = $('.checkFreeLoginTime').hasClass("notFree")? "false" : "true" ;
	    var timeElapsed = false;
	    var imagesTimer = setTimeout(function () {
			timeElapsed = true;
			done();
	    }, timeout);
	    $('<img />').attr('src', getRealDomain(domains[i]) + '/m/2/login/crossdomain?uid='+uid+"&freeLogin="+freeLogin+"&tag="+tag).load(function() {
 			imgload();
		}).error(function () {
			imgload();
		});
		function imgload() {
			if (!timeElapsed) {
				clearTimeout(imagesTimer);
				done();
			}
		}
	}
	function done() {
		domaincount++;
		if (domaincount >= domains.length) {
		    if(notJump==null || notJump!=true){
                jumpurlsubmit();
            }
		}
	}
}	


//跨域种cookie ,不进行页面跳转
function qqLogincookieHideImg(uid,jumpUrl,tag){
	//设置超时 时间
	var timeout = 1800;
	var domaincount = 0;
	for(var i = 0; i < domains.length; i++) {
		load();
	}
	function load() {
		var freeLogin = $('.checkFreeLoginTime').hasClass("notFree")? "false" : "true" ;
	    var timeElapsed = false;
	    var imagesTimer = setTimeout(function () {
			timeElapsed = true;
			done();
	    }, timeout);
	    $('<img />').attr('src', getRealDomain(domains[i]) + '/m/2/login/crossdomain?uid=' + uid+"&freeLogin="+freeLogin+"&tag="+tag).load(function() {
 			imgload();
		}).error(function () {
			imgload();
		});
		function imgload() {
			if (!timeElapsed) {
				clearTimeout(imagesTimer);
				done();
			}
		}
	}
	function done() {
		domaincount++;
		if (domaincount >= domains.length) {
			window.parent.location.href = jumpUrl;
			
//			jumpurlsubmit();
		}
	}
}

//跨域种cookie 
function logoutCleanCookie(){
	
	//设置超时 时间
	var timeout = 1800;
	var domaincount = 0;
	for(var i = 0; i < domains.length; i++) {
		load();
	}
	function load() {
	    var timeElapsed = false;
	    var imagesTimer = setTimeout(function () {
			timeElapsed = true;
			done();
	    }, timeout);
	    $('<img />').attr('src', getRealDomain(domains[i]) + '/m/2/logout/crossdomain').load(function() {
 			imgload();
		}).error(function () {
			imgload();
		});
		function imgload() {
			if (!timeElapsed) {
				clearTimeout(imagesTimer);
				done();
			}
		}
	}
	function done() {
		domaincount++;
		if (domaincount >= domains.length) {
			jumpurlsubmit();
		}
	}
}		

function jumpurlsubmit(){
	var form = document.createElement("form");
    var formName = "jumpform";
    form.style.display = "none";
    form.action="/pc/redirectJumpUrl";
    form.name = formName;  
    document.body.appendChild(form);
    form.submit();
}

function ucjump(funcName){
	var form = document.createElement("form");
    var formName = "jumpform";
    form.style.display = "none";
    form.action=curDomain+"/ucenter/redirectJumpUrl?funcion="+funcName;
    form.name = formName;  
    form.method= "GET";
    document.body.appendChild(form);
    var tempInput = document.createElement("input");
	 tempInput.type="hidden"; 
	 tempInput.name="funcion";
	 tempInput.value=funcName; //the　parameter　of　method　in　the　code　of　DispatchAction.　  
	 form.appendChild(tempInput);
     form.submit();
}

function getRealDomain(domain) {
    var schema = window.currentSchema;
    if(!window.currentSchema) {
        schema = "http://"; 
    }
    return schema + domain;
}